package exer;

import java.util.concurrent.TimeUnit;

/**
 * @author tongchen
 * @create 2023-01-14 13:43
 */
public class MyBlockingQueueTest {
    public static void main(String[] args) {
        MyBlockingQueue myBlockingQueue = new MyBlockingQueue();
        Thread t1 =new Thread(()->{
                    int num=0;
                    while(true){

                        try {
                            myBlockingQueue.put(num++);
                            System.out.println("放入了元素"+num);
                            TimeUnit.MILLISECONDS.sleep(10);
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
        });
        Thread t2 =new Thread(()->{
            int num=0;
            while(true){
                try {
                    myBlockingQueue.remove();
                    System.out.println("取出了元素"+(++num));
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }

        });
        t1.start();
        t2.start();
    }
}
